﻿Public Class editar_kit
    Dim qry As String
    Dim dataset As New DataSet
    Dim estado As String = "2"
    Dim ubicacionstr As String
    Dim id As String
    Dim flag As Boolean = False
    Dim ceditar As String
    Public Sub setid(ByVal id As Integer, ByVal ceditar As String)
        Me.id = id
        Me.ceditar = ceditar
        flag = True
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
    Private Sub editar_kit_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Text = "Editar Kit"
        Me.Icon = (My.Resources.favicon)
        CargarCombobox("select * from bodegas", ubicacion, "bod_nombre", "bod_nombre")
        CargarCombobox("select * from estudios where est_estado='1'", estudio, "est_id", "est_nombre")
        CargarCombobox("select * from estado_kit", ComboBox1, "etdo_id", "etdo_nombre")
        If estudio.Items.Count = 0 Then
            MsgBox("No hay Estudios Disponibles, Ingrese uno antes de continuar", MsgBoxStyle.Information)
            Me.Close()
        End If
        RadioButton2.Checked = True
        ubicacionstr = TextBox1.Text
        Consulta(ceditar, dataset)
        estudio.SelectedValue = dataset.Tables("data").Rows(0)("est_id")
        ComboBox1.SelectedValue = dataset.Tables("data").Rows(0)("etdo_id")
        vencimiento.Value = dataset.Tables("data").Rows(0)("kit_fecha_vencimiento")

    End Sub

    Private Sub estudio_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles estudio.SelectedIndexChanged
        Consulta("select est_direccion from estudios where est_id='" & estudio.SelectedValue & "'", dataset)
        TextBox1.Text = dataset.Tables("data").Rows(0)(0)
    End Sub

    Private Sub btn_aceptar_Click(sender As System.Object, e As System.EventArgs) Handles btn_aceptar.Click
        qry = "update kit set est_id='" & estudio.SelectedValue & "',etdo_id='" & ComboBox1.SelectedValue & "',kit_fecha_vencimiento='" & vencimiento.Value & "',kit_ubicacion='" & ubicacionstr & "' where kit_id='" & id & "'"
        EjecutaConsulta(qry)
        'registro movimiento
        registro("modificar", login.usuario.id, main.modulo.kit)
        man_kits.actualizar()
        Me.Close()
    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged

        ubicacion.Enabled = True
        TextBox1.Enabled = False
    End Sub

    Private Sub RadioButton2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton2.CheckedChanged
        ubicacion.Enabled = False
        TextBox1.Enabled = True
        ubicacionstr = TextBox1.Text
    End Sub

    Private Sub ubicacion_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ubicacion.SelectedIndexChanged
        ubicacionstr = ubicacion.SelectedValue
    End Sub
End Class